﻿<cfsilent>
	<cfscript>
	
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		response = structNew();
		structInsert(response, "success", false, true);
		
		studentId = event.getArg("StuID");
		subjectDir = event.getArg("SubDir");
		
		if ( len(studentId) and len(subjectDir) ) {
			
			transaction {
				
				sql = "SELECT a.stu_id 
						FROM t_student a 
						WHERE a.stu_id = :studentId ";
						
				queryObj = new Query( datasource=application.dnsMaster ) ;
				queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
				
				rs_student= queryObj.execute( sql=sql ).getResult();	
				
				if (rs_student.recordCount GT 0) {
					
					sql = "UPDATE t_student a 
							SET 
								a.sbj_direction = :subjectDir  
							WHERE a.stu_id = :studentId  ";
							
					queryObj = new Query( datasource=application.dnsMaster ) ;
					queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="subjectDir", value=subjectDir, cfsqltype="cf_sql_varchar" );
					queryObj.execute( sql=sql );
					
					sql = "SELECT a.stu_id,a.sbj_direction 
							FROM t_student a 
							WHERE a.stu_id = :studentId ";
							
					queryObj = new Query( datasource=application.dnsMaster ) ;
					queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
					
					rs_students= queryObj.execute( sql=sql ).getResult();	

					structInsert(response, "StudentID", rs_students.stu_id, true);	
					structInsert(response, "SubjectDirection", rs_students.sbj_direction, true);	
					
					structInsert(response, "success", true, true);
				}
				
			}
			
		}
		

	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>